<?php


namespace App\HttpController\Api\V1;


use Smalls\VideoTools\VideoManager;

class Video extends ApiBaseController
{

    private $type = [
        'Bili'            => ['b23.tv', 'www.bilibili.com'],
        'DouYin'          => ['douyin.com', 'iesdouyin.com'],
        'HuoShan'         => ['huoshan.com'],
        'KuaiShou'        => ['ziyang.m.kspkg.com', 'kuaishou.com', 'gifshow.com', 'chenzhongtech.com', 'v.kuaishouapp.com'],
        'LiVideo'         => ['www.pearvideo.com'],
        'MeiPai'          => ['www.meipai.com'],
        'MoMo'            => ['immomo.com'],
        'PiPiGaoXiao'     => ['ippzone.com'],
        'PiPiXia'         => ['pipix.com'],
        'QuanMingGaoXiao' => ['longxia.music.xiaomi.com'],
        'ShuaBao'         => ['h5.shua8cn.com', 'm.shua8cn.com'],
        'TouTiao'         => ['toutiaoimg.com', 'toutiaoimg.cn'],
        'WeiShi'          => ['weishi.qq.com'],
        'XiaoKaXiu'       => ['mobile.xiaokaxiu.com'],
        'XiGua'           => ['xigua.com'],
        'ZuiYou'          => ['izuiyou.com'],
        'WeiBo'           => ['weibo.com', 'weibo.cn'],
        'newweibo'        => ['video.weibo.com/show'],
        'MiaoPai'         => ['miaopai.com'],
        'QQVideo'         => ['m.v.qq.com'],
        'TaoBao'          => ['h5.m.taobao.com', 'm.tb.cn'],
    ];

    public function clearWatermark(){

        try {
            $url = $this->request()->getRequestParam("url");
            $method = "";
            foreach ($this->type as $key => $item){

                foreach ($item as $value){

                    if(getTopHost($url)==$value){
                        $method = $key;
                    }
                }

            }
            if(!$method){
                return   $this->returnData(500,[],"请输入正确的视频平台连接");
            }

            $res = VideoManager::$method()->start($url);

            return   $this->returnData(200,$res);

        }catch (\Exception $e){

            $msg = "";
            if($e->getMessage() == "ErrorVideo : URL校验失败"){
                $msg = "请输入正确的视频平台连接";
            }
            var_dump($e->getMessage());
            return   $this->returnData(500,[],$msg);
        }


    }


}